package org.ch00.test09.demo02;


/*
 *
 *@author XCH
 *@date 2025 - 03 - 10 - 19:40
 *
 */
public class MainTest {
    public static void main(String[] args) {
        System.out.println("程序开始");
        // 创建三个线程，分别计算1到100、101到900、901到1000的求和
        SumRunnable runnable1 = new SumRunnable(1, 100);
        SumRunnable runnable2 = new SumRunnable(101, 900);
        SumRunnable runnable3 = new SumRunnable(901, 1000);

        Thread thread1 = new Thread(runnable1);
        Thread thread2 = new Thread(runnable2);
        Thread thread3 = new Thread(runnable3);

        // 启动线程
        thread1.start();
        thread2.start();
        thread3.start();

        // 等待线程执行完毕
        try {
            thread1.join();
            thread2.join();
            thread3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 计算最终结果
        long totalSum = runnable1.getSum() + runnable2.getSum() + runnable3.getSum();
        System.out.println("结果: " + totalSum);

    }
}
